// releasePage/pages/homePageInfo/homePageInfo.js
import throttle from '../../../utils/throttle.js';
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        review: '', //审核编辑标记位
        id: '',
        ipxBottom: 0,
        current: 0,
        btnInfo: Number,
        showBtn: true,
        // ft信息
        ftSceneId: '',
        ftScene: '',
        ftDiscription: '',
        ftAddress: '',
        ftOperator: '',
        ftOperatorId: '',
        // ftnetworktype: '',
        // ftoperatorinfo: '',
        //路线
        ftLineName: '',
        ftLineDiscription: '',
        webLink: '',
        operatorType: '',
        networktype: '',
        operator: '',
        ftLineOperatorId: '',
        // nfc信息
        nfcAddressName: '',
        nfcDiscription: '',
        nfcAddress: '',
        nfcCompany: '',
        nfcCompanyId: '',
        //路线
        nfcLineName: '',
        nfcLineDiscription: '',
        deviceSupport: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (app.globalData.isIpx) {
            this.setData({
                ipxBottom: 34,
            });
        }
        if (!options.id) {
            wx.setNavigationBarTitle({
                title: '录入/' + app.globalData.addressBack,
            });
        }
        this.setData({
            current: options.current || 0,
            id: options.id,
            review: options.review || '',
        });
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    changeCurrent(e) {
        this.setData({
            current: e.detail.current,
        });
    },
    changeswiperCurrent(e) {
        let _that = this;
        let index = e.currentTarget.dataset.index;
        if (!_that.data.id && index != _that.data.current) {
            wx.showModal({
                title: '提示',
                content: '确认切换至发布另一种数据类型？',
                success: function (res) {
                    if (res.confirm) {
                        _that.setData({
                            current: index,
                            btnInfo: Number,
                            // ft信息
                            ftScene: '',
                            ftDiscription: '',
                            ftAddress: '',
                            //ft路线
                            ftLineName: '',
                            ftLineDiscription: '',
                            webLink: '',
                            operator: '',
                            networktype: '',
                            // nfc信息
                            nfcAddressName: '',
                            nfcDiscription: '',
                            nfcAddress: '',
                            nfcCompany: '',
                            nfcCompanyId: '',
                            //nfc路线
                            nfcLineName: '',
                            nfcLineDiscription: '',
                            deviceSupport: '',
                        });
                    }
                },
            });
        } else {
            return;
        }
    },
    //隐藏提交按钮
    hideBtn() {
        this.setData({
            showBtn: false,
        });
    },
    //显示提交按钮
    showBtn() {
        this.setData({
            showBtn: true,
        });
    },
    // 阻止swiper滚动
    catchTouchMove: function (res) {
        return false;
    },
    // ft组件传值（按钮事件）
    getBtnInfo(e) {
        this.setData({
            btnInfo: e.detail,
        });
    },
    // 提交
    submit(e) {
        let _that = this;
        if (app.visitorPublish()) return; //游客发布限制
        let arr = [];
        if (_that.data.btnInfo == 0) {
            var ft = _that.selectComponent('#ft-content');
            arr = ['ftPoint', 'count'];
            wx.showModal({
                title: '提示',
                content: '确认提交？',
                success: function (res) {
                    if (res.confirm) {
                        ft.submit(_that.data.review);
                        _that.backLoading(arr);
                    }
                },
            });
        } else if (_that.data.btnInfo == 1) {
            var ftline = _that.selectComponent('#ft-line');
            arr = ['ftLine', 'count'];
            wx.showModal({
                title: '提示',
                content: '确认提交？',
                success: function (res) {
                    if (res.confirm) {
                        ftline.submit(_that.data.review);
                        _that.backLoading(arr);
                    }
                },
            });
        } else if (_that.data.btnInfo == 2) {
            var nfc = _that.selectComponent('#nfc-content');
            arr = ['nfcPoint', 'count'];
            wx.showModal({
                title: '提示',
                content: '确认提交？',
                success: function (res) {
                    if (res.confirm) {
                        nfc.submit(_that.data.review);
                        _that.backLoading(arr);
                    }
                },
            });
        } else if (_that.data.btnInfo == 3) {
            var nfcline = _that.selectComponent('#nfc-line');
            arr = ['nfcLine', 'count'];
            wx.showModal({
                title: '提示',
                content: '确认提交？',
                success: function (res) {
                    if (res.confirm) {
                        nfcline.submit(_that.data.review);
                        _that.backLoading(arr);
                    }
                },
            });
        } else if (_that.data.btnInfo == 5) {
            return;
        } else {
            wx.showToast({
                title: '请将信息填写完整',
                icon: 'none',
                duration: 1500,
            });
            return;
        }
    },
    backLoading(e) {
        let _that = this;
        if (!_that.data.review) {
            _that.setData({
                btnInfo: 5,
            });
            let pages = getCurrentPages(); //当前页面栈
            let prevPage = pages[pages.length - 2]; //上一页面
            let prevPage2 = pages[pages.length - 3]; //上一页面
            setTimeout(function () {
                prevPage.refresh(e);
                if (_that.data.id) {
                    prevPage2.refresh(e);
                }
            }, 1000);
            setTimeout(function () {
                wx.navigateBack({
                    delta: 1, // 返回上一级页面。
                });
            }, 2000);
        }
    },
});
